// (c) Copyright 2013-2014 Stephen Gold <sgold@sonic.net>
// Distributed under the terms of the GNU General Public License

/*
 This file is part of the Bats Game.

 The Bats Game is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by the
 Free Software Foundation, either version 3 of the License, or (at your
 option) any later version.

 The Bats Game is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.

 You should have received a copy of the GNU General Public License
 along with the Bats Game.  If not, see <http://www.gnu.org/licenses/>.
 */
package bats.control;

import bats.missile.PenetrateControl;
import java.util.logging.Logger;
import jme3utilities.MyControl;

/**
 * Access for the "enabled" state of Bats Game scene-graph controls. Aside from
 * test cases, all methods here should be public and static.
 *
 * @author Stephen Gold <sgold@sonic.net>
 */
final public class BatsControl {
    // *************************************************************************
    // constants

    /**
     * message logger for this class
     */
    final private static Logger logger =
            Logger.getLogger(BatsControl.class.getName());
    // *************************************************************************
    // constructors

    /**
     * A private constructor to inhibit instantiation of this class.
     */
    private BatsControl() {
    }
    // *************************************************************************
    // new methods exposed

    /**
     * Test whether a scene-graph control is enabled.
     *
     * @param control which control to test (not null)
     * @return true if the control is enabled, otherwise false
     */
    public static boolean isEnabled(Object control) {
        if (control instanceof PenetrateControl) {
            return ((PenetrateControl) control).isEnabled();
        } else {
            return MyControl.isEnabled(control);
        }
    }

    /**
     * Check whether a scene-graph control is compatible with isEnabled() and
     * setEnabled().
     *
     * @param control which control to validate
     * @return true if compatible, false if incompatible
     */
    public static boolean isValid(Object control) {
        return control instanceof PenetrateControl
                || MyControl.isValid(control);
    }

    /**
     * Alter the enabled state of a scene-graph control.
     *
     * @param control which control to alter
     * @param newState true means enable the control, false means disable it
     */
    public static void setEnabled(Object control, boolean newState) {
        if (control instanceof PenetrateControl) {
            ((PenetrateControl) control).setEnabled(newState);
        } else {
            MyControl.setEnabled(control, newState);
        }
    }
}